#include <unordered_map>
#include <string>
#include <cstdio>
#include <iostream>

#define CONF_RECORD_XMACROS   \
    X(CONF_RECORD_START_CONF, "confrecord.startconf") \
    X(CONF_RECORD_END_CONF, "confrecord.endconf") \
    X(CONF_RECORD_CHANGE_LAYOUT, "confrecord.changelayout") \
    X(CONF_RECORD_ACTIVATE_ENTER_CONF, "confrecord.activate.enterconf") \
    X(CONF_RECORD_PASSIVE_ENTER_CONF, "confrecord.passive.enterconf") \
    X(CONF_RECORD_ACTIVATE_EXIT_CONF, "confrecord.activate.exitconf") \
    X(CONF_RECORD_PASSIVE_EXIT_CONF, "confrecord.passive.exitconf") \
    X(CONF_RECORD_ACCESS_EMCEE, "confrecord.access.emcee") \
    X(CONF_RECORD_RELEASE_EMCEE, "confrecord.release.emcee") \
    X(CONF_RECORD_MUTED, "confrecord.muted") \
    X(CONF_RECORD_UNMUTED, "confrecord.unmuted") \
    X(CONF_RECORD_START_PUSH_SCREEN, "confrecord.start.pushscreen") \
    X(CONF_RECORD_STOP_PUSH_SCREEN, "confrecord.stop.pushscreen")

enum ActionType {
    UNVALID   = -1,
#define X(name, value) name,
    CONF_RECORD_XMACROS
#undef X
    CONF_RECORD_TYPE_COUNT,
};

struct EnumClassHash {
    template <typename T>
    std::size_t operator()(T t) const {
        return static_cast<std::size_t>(t);
    }
};

const std::unordered_map<ActionType, std::string, EnumClassHash> confRecordEventMap = {
    #define X(name, value) {name, value},
    CONF_RECORD_XMACROS
    #undef X
    {UNVALID, "UNVALID"},
};

int main() {
    for(int i = -1; i < CONF_RECORD_TYPE_COUNT; i++){
        ActionType type = static_cast<ActionType>(i);
        std::string typestr;
        auto it = confRecordEventMap.find(type);
        if (it != confRecordEventMap.end()){
            typestr = it->second;
            
        } else {
            std::cout<<"no fount "<<type<<std::endl;
            continue;
        }
        printf("conf event type[%d] is %s\n", type, typestr.c_str());
    }


        // 或者更简单的遍历方式：
    std::cout << "\nAlternative way to iterate:\n";
    for (const auto& pair : confRecordEventMap) {
        printf("conf event type[%d] is %s\n", static_cast<int>(pair.first), pair.second.c_str());
    }
}